import MPRequest from '../utils/request'
export const baseUrl = process.env.HOST

/**
 * 获取AccessToken的登录接口
 * @param {*} data
 */
export const authApi = async function (data) {
  console.log('authApi requesting...')
  const res = await MPRequest.post('/authorize', data)
  return res
}

// 获取首页信息接口
export const getSite = function () {
  return MPRequest.get(`site/index`)
}

// 获取首页信息接口
export const getWorktypes = () => {
  return MPRequest.get(`work/type/index`)
}

// 获取首页信息接口
export const attachUpload = function (data, type) {
  return MPRequest.upload(`${baseUrl}/attachs/upload`, data, type)
}

// 获取首页信息接口
export const beforeAttachUpload = function (data, type) {
  return MPRequest.beforeUpload(`${baseUrl}/attachs/upload`, data, type)
}

// 获取AccessToken的登录接口
export const loginApi = async function (data) {
  console.log('loginApi requesting...')
  const res = await MPRequest.post('/passport/login/mp', data)
  return res
}

// 发送短信验证码
export const sendcodeApi = function (data) {
  const res = MPRequest.post('/sms/captcha', data)
  return res
}

// 获取首页信息接口
export const getHomeApi = () => {
  return MPRequest.get(`home`)
}

// 获取新闻中心首页
export const getRecommendsApi = (data) => {
  return MPRequest.get(`home/recommend/index`, data)
}

// 获取新闻中心首页
export const getNewestApi = (data) => {
  return MPRequest.get(`home/recommend/newest`, data)
}

// 获取俱乐部资料信息接口
export const getClubApi = () => {
  return MPRequest.get(`ofc`)
}

// 获取赛季赛程接口
export const getSeasonMatchsApi = (data) => {
  return MPRequest.get(`ofc/match/index`, data)
}

// 获取赛季赛程接口
export const getCmsMatchsApi = () => {
  return MPRequest.get(`cms/match/index`)
}

// 获取页面tab
export const getPageTabsApi = (name) => {
  return MPRequest.get(`pages/tabs/index?position=${name}`)
}

// 获取新闻中心首页
export const getNewsCenterApi = () => {
  return MPRequest.get(`cms/default/index`)
}

// 获取文章详情接口
export const getArticleApi = (id) => {
  return MPRequest.get(`cms/article/view?id=${id}`)
}

// 获取秩序内容接口
export const getNoticeApi = () => {
  return MPRequest.get(`cms/notice/index`)
}

// 获取文章详情接口
export const getArticleList = (params) => {
  return MPRequest.get(`cms/article/index`, params)
}

// 获取认证用户信息
export const getAuthentApi = () => {
  return MPRequest.get(`user/authent/index`)
}

// 提交成员认证信息
export const postAuthentApi = (data) => {
  return MPRequest.post(`user/authent/update`, data)
}

// 获取会员用户信息
export const getMemberApi = () => {
  return MPRequest.get(`user/member/index`)
}

// 提交会员认证信息
export const postMemberApi = (data) => {
  return MPRequest.post(`user/member/update`, data)
}

// 获取活动列表接口
export const getActivityList = (params) => {
  return MPRequest.get(`activity/default/index`, params)
}

// 获取活动详情接口
export const getActivityApi = (id) => {
  return MPRequest.get(`activity/default/view?id=${id}`)
}

// 获取活动详情接口
export const getEnrollFormApi = (id) => {
  return MPRequest.get(`activity/enroll/index?id=${id}`)
}

// 提交报名信息接口
export const postEnrollFormApi = (id, data) => {
  return MPRequest.post(`activity/enroll/update?id=${id}`, data)
}

// 获取签到信息接口
export const getSigninApi = () => {
  return MPRequest.get(`user/signin/index`)
}

// 获取签到信息接口
export const getSigninViewApi = () => {
  return MPRequest.get(`user/signin/view`)
}

// 提交签到信息接口
export const postSigninApi = (data) => {
  return MPRequest.post(`user/signin/create`, data)
}

//= ======================================

// 需要结算的商品查询
export const getDownloadFile = function (data) {
  return MPRequest.get(`team/download/index`, data)
}

// 解除绑定手机号接口
export const securitySmsApi = function (type) {
  return MPRequest.post(`passport/sms/${type}`)
}

// 绑定手机号接口
export const bindMobileApi = function (data) {
  return MPRequest.post(`passport/bind/mobile`, data)
}

// 解除绑定手机号接口
export const unbindMobileApi = function () {
  return MPRequest.post(`passport/unbind/mobile`)
}

// 个人中心
export const accountSmsCheck = function (data) {
  return MPRequest.post(`passport/sms/validate`, data)
}

// 个人中心
export const securityEnvCheck = function (data) {
  return MPRequest.post(`passport/account/check`, data)
}

// 个人中心
export const logoutApply = function () {
  return MPRequest.post(`passport/logout/apply`)
}

// 个人中心
export const logoutProgress = function () {
  return MPRequest.get(`passport/logout/status`)
}

// 个人中心
export const getProfileFormOptions = function (attribute = null) {
  return MPRequest.get(`user/profile/options`, attribute ? {
    id: attribute
  } : null)
}

// 个人中心
export const updateProfile = function (data) {
  return MPRequest.post(`user/profile/update`, data)
}

// 个人中心
export const updateAccount = function (data) {
  return MPRequest.post(`passport/account/update`, data)
}

// 我的记工簿
export const mineBooks = function (data) {
  return MPRequest.get(`user/book/index`, data)
}

// 个人中心
export const userAuthent = function (data) {
  return MPRequest.post(`user/authent/create`, data)
}

// 个人中心
export const getMemberInfo = function () {
  return MPRequest.get(`user/home`)
}

// 检索列表
export const getSearchList = function (params) {
  return MPRequest.get(`/search`, params)
}
